
package model.persistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class PostgresTransactionManager extends AbstractTransactionManager{

    public PostgresTransactionManager(String username, String password, String database){
        super(username, password, database);  //chama a superclasse
    }

    protected Connection createConnection() throws ClassNotFoundException, SQLException {
        Class.forName("org.postgresql.Driver");//so esta classe conhece o driver para a conexao com o PostGres
        Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost/" + this.getDatabase() + "?user=" + this.getUsername() + "&password=" + this.getPassword());
        return connection;
    }

    protected DAO createDAO(String entity) throws ClassNotFoundException, IllegalAccessException, InstantiationException, CloneNotSupportedException{
        DAOFactory factory = AbstractDAOFactory.getDAOFactory(AbstractDAOFactory.POSTGRES);
        DAO dao = factory.createDAO(entity);
        return dao;
    }

    

}
